home *** CD-ROM | disk | FTP | other *** search
- /* See the file Distribution for distribution terms.
- (c) Copyright 1994 Ari Halberstadt */
-
- /* Utilities for stand-alone thread library.
- 94/02/10 aih - created */
-
- #if ! WINTER_SHELL
-
- #include <string.h>
- #include "ThreadUtil.h"
- #include "ExceptionLib.h"
-
- Ptr StkLowPt : 0x110;
- short _profile_depth;
-
- /*----------------------------------------------------------------------------*/
- /* assertions */
- /*----------------------------------------------------------------------------*/
-
- int assertfailed(void)
- {
- Debugger();
- return(0);
- }
-
- /*----------------------------------------------------------------------------*/
- /* memory operations */
- /*----------------------------------------------------------------------------*/
-
- void *memclr(void *p, size_t n)
- {
- return(memset(p, 0, n));
- }
-
- Boolean HandleValid(void *h)
- {
- return(h != NULL);
- }
-
- Boolean HandleValidSize(void *h, size_t n)
- {
- return(HandleValid(h) && GetHandleSize(h) >= n);
- }
-
- void *HandleBeginClear(size_t n)
- {
- void *h;
-
- h = NewHandleClear(n);
- FailNIL(h);
- return(h);
- }
-
- void HandleEnd(void *h)
- {
- DisposeHandle(h);
- }
-
- Boolean PtrValid(void *p)
- {
- return(p != NULL);
- }
-
- size_t PtrSize(void *p)
- {
- return(GetPtrSize(p));
- }
-
- void *PtrBegin(size_t n)
- {
- void *p;
-
- p = NewPtr(n);
- FailNIL(p);
- return(p);
- }
-
- void PtrEnd(void *p)
- {
- DisposePtr(p);
- }
-
- /*----------------------------------------------------------------------------*/
- /* low-memory global access (must not move memory) */
- /*----------------------------------------------------------------------------*/
-
- Ptr GetCurStackBase(void)
- {
- return(CurStackBase);
- }
-
- void SetStkLowPt(Ptr p)
- {
- StkLowPt = p;
- }
-
- /*----------------------------------------------------------------------------*/
- /* linked list operations */
- /*----------------------------------------------------------------------------*/
-
- /* macros for accessing next item */
- #define deref(x) (**(LLHandle) (x))
- #define next(x) (deref(x).hnext)
-
- /* true if a valid item */
- Boolean LLHValid(LLObjectType item)
- {
- return(HandleValidSize(item, sizeof(LLType)));
- }
-
- /* return next item in list */
- LLObjectType LLHNext(LLObjectType item)
- {
- require(! item || LLHValid(item));
- return(item ? next(item) : NULL);
- }
-
- /* appends the item after the end of the list. Returns head of list. */
- LLObjectType LLHAppend(LLObjectType head, LLObjectType item)
- {
- LLObjectType tail;
-
- if (! head)
- head = item;
- else {
- for (tail = head; next(tail); tail = next(tail))
- ;
- next(tail) = item;
- }
- return(head);
- }
-
- /* Removes the item from the list. Does nothing if the item couldn't be found.
- Returns the new head of the list. */
- LLObjectType LLHDelete(LLObjectType head, LLObjectType item)
- {
- require(! head || LLHValid(head));
- require(! item || LLHValid(item));
- if (head && item) {
- if (head == item)
- head = next(head);
- else {
- LLObjectType prev = head;
- while (prev && next(prev) != item)
- prev = next(prev);
- check(prev != item);
- if (prev)
- next(prev) = next(item);
- }
- }
- ensure(! head || LLHValid(head));
- return(head);
- }
-
- #endif /* WINTER_SHELL */
-